<%--
功能: 对话框控件
--%>
<%@ tag body-content="scriptless"%>
<%@	taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@	taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ attribute name="id" required="true"  type="java.lang.String" description="对话框识别ID，提示：可以用ui_dialog_${id}的jquery对象调用该对话框"%>
<%@ attribute name="title" required="true"  type="java.lang.String" description="对话框标题"%>
<%@ attribute name="width" required="true"  type="java.lang.String" description="宽度"%>
<%@ attribute name="height" required="true"  type="java.lang.String" description="高度"%>
<%@ attribute name="buttons" required="false"  type="java.lang.String" description="需要的按钮，格式如：name1:action1,name2:action2"%>
<%@ attribute name="url" required="false"  type="java.lang.String" description="[ajax]窗口的内容使用ajax load方式载入；否则使用TAG中间的内容"%>
<%@ attribute name="isKeepScene" required="false"  type="java.lang.Boolean" description="[ajax]是否保持当前场景,用于ajax load，如果true则每次open dialog不会重新加载页面，否则每次open dialog均会重新加载页面。默认false"%>
<%@ attribute name="callback" required="false"  type="java.lang.String" description="[ajax]载入成功时回调函数"%>

<c:set var="ui_dialog" value="true" scope="request"/>
<div id="divDlg${id}" style="visibility:hidden;position:absolute;overflow: auto;">
	<jsp:doBody />
</div>
<script type="text/javascript">
var ui_dialog_${id};
var ui_dialog_${id}_hasKeepScene = false;
var ui_dialog_${id}_needKeepScene = false;
<c:if test="${isKeepScene == true}">
	ui_dialog_${id}_needKeepScene = true;
</c:if>

$j(document).ready(function(){
	ui_dialog_${id} = $j("#divDlg${id}"); 
}); 
/**
 * 显示dialog
 * @param {Object} param (可选) 发送至服务器的 key/value 数据;JSON格式
 */
function dlg${id}_show(param)
{
	ui_dialog_${id}.css("visibility","visible");
	<c:if test="${not empty url}">
		if(ui_dialog_${id}_needKeepScene && ui_dialog_${id}_hasKeepScene){
			//如果需要保持场景，且已经ajax load 
			//do nothing
		}else{
			ui_dialog_${id}.empty();
			if(!param)param={}; 
			ui_dialog_${id}.loading().load("${url}",param${empty callback?'':','}${callback});
			if(ui_dialog_${id}_needKeepScene){
				ui_dialog_${id}_hasKeepScene = true;
			}
		}	
	</c:if>
	
	ui_dialog_${id}.dialog({ 
		title:"${title}", 
		modal: true, 
		height:${height},
		width:${width}, 
		bgiframe: true,
		buttons: {${buttons}},
	    overlay: { opacity: 0.5, background: "black" } 
	});
	
	
	ui_dialog_${id}.dialog("open");
	
}


function dlg${id}_close()
{
	ui_dialog_${id}.dialog("close");
}

/**
 * 禁用dialog buttons项中的某一个button
 * @param btnValue  button content value, e.g. <button>btnValue</button>
 */
function dlg${id}_disableBtn(btnValue){
	ui_dialog_${id}.filter( function(){ $j(":button:contains("+btnValue+")").attr("disabled","true").attr("style", "background:#E6E6E6;border:1px solid #ccc;color:#bbb;"); } );
}
/**
 * 启用dialog buttons项中的某一个button
 * @param btnValue  button content value, e.g. <button>btnValue</button>
 */
function dlg${id}_enableBtn(btnValue){
	ui_dialog_${id}.filter( function(){ $j(":button:contains("+btnValue+")").removeAttr("disabled").removeAttr("style"); } );
}
</script>